package com.esri.core.internal.a.a;

import android.graphics.BitmapFactory;
import com.esri.android.map.ags.ArcGISLayerInfo;
import com.esri.core.internal.io.handler.h;
import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.internal.tasks.d;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.Legend;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class a extends d<Boolean> {
    private static final long serialVersionUID = 1;
    private ArcGISLayerInfo[] a;

    public a(ArcGISLayerInfo[] arcGISLayerInfoArr, String str, UserCredentials userCredentials, TaskListener<Boolean> taskListener) {
        super(null, str, userCredentials, taskListener);
        this.a = arcGISLayerInfoArr;
    }

    public a(ArcGISLayerInfo[] arcGISLayerInfoArr, String str, UserCredentials userCredentials) {
        this(arcGISLayerInfoArr, str, userCredentials, null);
    }

    @Override // com.esri.core.internal.tasks.a
    /* renamed from: a */
    public Boolean execute() throws Exception {
        ArcGISLayerInfo[] arcGISLayerInfoArr;
        ArcGISLayerInfo arcGISLayerInfo;
        ArcGISLayerInfo[] arcGISLayerInfoArr2 = this.a;
        if (arcGISLayerInfoArr2 == null || arcGISLayerInfoArr2.length == 0) {
            return Boolean.TRUE;
        }
        HashMap hashMap = new HashMap();
        for (ArcGISLayerInfo arcGISLayerInfo2 : this.a) {
            if (arcGISLayerInfo2 != null) {
                hashMap.put(Integer.valueOf(arcGISLayerInfo2.getId()), arcGISLayerInfo2);
            }
        }
        JsonParser a = h.a(this.serviceURL + "/legend", (Map<String, String>) null, getServiceCredentials());
        if (!com.esri.core.internal.util.d.c(a)) {
            return Boolean.FALSE;
        }
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPurgeable = true;
        int i = -1;
        while (a.nextToken() != JsonToken.END_OBJECT) {
            String currentName = a.getCurrentName();
            a.nextToken();
            if ("layers".equals(currentName) && a.getCurrentToken() == JsonToken.START_ARRAY) {
                while (a.nextToken() != JsonToken.END_ARRAY) {
                    while (a.nextToken() != JsonToken.END_OBJECT) {
                        ArrayList arrayList = new ArrayList();
                        String currentName2 = a.getCurrentName();
                        a.nextToken();
                        if ("layerId".equals(currentName2)) {
                            i = a.getIntValue();
                        } else if ("legend".equals(currentName2)) {
                            if (a.getCurrentToken() == JsonToken.START_ARRAY) {
                                while (a.nextToken() != JsonToken.END_ARRAY) {
                                    String str = null;
                                    byte[] bArr = null;
                                    while (a.nextToken() != JsonToken.END_OBJECT) {
                                        String currentName3 = a.getCurrentName();
                                        a.nextToken();
                                        if ("label".equals(currentName3)) {
                                            str = a.getText();
                                        } else if ("imageData".equals(currentName3)) {
                                            bArr = a.getBinaryValue();
                                        } else {
                                            a.skipChildren();
                                        }
                                    }
                                    if (str != null && bArr != null) {
                                        arrayList.add(new Legend(BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options), str));
                                    }
                                }
                                if (i >= 0 && (arcGISLayerInfo = (ArcGISLayerInfo) hashMap.get(Integer.valueOf(i))) != null) {
                                    arcGISLayerInfo.setLegend(arrayList);
                                }
                                i = -1;
                            }
                        } else {
                            a.skipChildren();
                        }
                    }
                }
            }
        }
        return Boolean.TRUE;
    }
}
